﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace MyWebApp
{
    public class MvcApplication : System.Web.HttpApplication
    {
        private static ILog log;
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log.config"));
            log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            log.InfoFormat("Application Start");

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

        }
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = Server.GetLastError();
            if (objErr.Message.Contains("File does not exist.") || objErr.Message.Contains("文件不存在"))
            {
                log.ErrorFormat("{0} {1}", objErr.Message, HttpContext.Current.Request.Url.ToString());
            }
            else
            {
                log.Error("Application Error! ", objErr);
            }
            Server.ClearError();
        }

       
    }
}
